<template>
    <div class="goodsinfo-container">

        <transition @before-enter="beforeEnter" @enter="enter" @after-enter="afterEnter">
            <div class="ball" v-show="ballFlag" ref="ball">    </div>
        </transition>

    

        <div class="mui-card">
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
					      <swiper-box :isfull="false" v-bind:lunbotuList="lunbotuList"></swiper-box>
					</div>
				</div>
		</div>


        <div class="mui-card">
				<div class="mui-card-header">{{goodsinfo.title}}</div>
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						<p class="price">
                            市场价:<del>￥{{goodsinfo.market_price}}</del>&nbsp;&nbsp;销售价:<span class="now_price">￥{{goodsinfo.sel_price}}</span>
                        </p>

                        <p>
                            
                            购买数量:<goddsinfo-number :max="goodsinfo.stock_quantity" @getCount="getSelectedCount"></goddsinfo-number>
                            
                        </p>
                        <p>
                            <mt-button type="primary" size="small">立即购买</mt-button>
                            <mt-button type="danger" @click="addShopCar"  size="small">加入购物车</mt-button>
                        </p>
					</div>
				</div>
			</div>
            

               <div class="mui-card">
				<div class="mui-card-header">商品的参数</div>
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						<p>商品货号:{{goodsinfo.goods_no}}</p>
                        <p>库存情况:{{goodsinfo.stock_quantity}}件</p>
                        <p>上架时间:{{goodsinfo.add_time}}</p>
					</div>
				</div>
				<div class="mui-card-footer">
                    <mt-button type="primary"  @click="goDesc(id)"  size="large" plain>图文介绍</mt-button>
                    <mt-button type="danger" @click="goComment(id)" size="large" plain>商品评论</mt-button>
                </div>
			</div>
    </div>
</template>



<script>
import Swiper from "../subcomponents/Swiper.vue";
import GoodsInfoNumber from "./GoodsInfo_Number.vue";
export default {
  data() {
    return {
      lunbotuList: [],
      id: this.$route.params.id,
      goodsinfo: {},
      ballFlag: false,
      selectCount: 1
    };
  },
  created() {
    this.getLunbo();
    this.getGoodsInfo();
  },
  methods: {
    getSelectedCount(count) {
      this.selectCount = count;
      console.log("getSelectedCount count=" + count);
    },
    beforeEnter(el) {
      el.style.transform = "translate(0,0)";
    },
    enter(el, done) {
      el.offsetWidth;
      const ballPostion = this.$refs.ball.getBoundingClientRect();
      const badgePosion = document
        .getElementById("badge")
        .getBoundingClientRect();

      const xDist = badgePosion.left - ballPostion.left;
      const yDist = badgePosion.top - ballPostion.top;

      el.style.transform = `translate(${xDist}px ,${yDist}px)`;
      el.style.transition = "all 0.5s cubic-bezier(.17,.67,.83,.67)";
      done();
    },
    afterEnter(el) {
      this.ballFlag = !this.ballFlag;
    },
    addShopCar() {
      this.ballFlag = !this.ballFlag;
      var goodsinfo = {
        id: this.id,
        count: this.selectCount,
        price: this.goodsinfo.sel_price,
        selected: true
      };
      this.$store.commit("addToCar",goodsinfo)
    },
    goDesc(id) {
      this.$router.push({ name: "goodsdesc", params: { id } });
    },
    goComment(id) {
      this.$router.push({ name: "goodscomment", params: { id } });
    },
    getLunbo() {
      this.lunbotuList = [
        {
          image:
            "http://fuss10.elemecdn.com/3/1e/42634e29812e6594c98a89e922c60jpeg.jpeg",
          w: 600,
          h: 400
        },
        {
          image:
            "http://fuss10.elemecdn.com/1/c5/95c37272d3e554317dcec1e17a9f5jpeg.jpeg",
          w: 600,
          h: 400
        }
      ];
      this.$http
        .get("https://www.baidu.com/?tn=62095104_7_oem_dg")
        .then(result => {
          console.log(result);
        });
    },
    getGoodsInfo() {
      this.goodsinfo = {
        id: 1,
        title: "Apple iPhone X (A1865) 64GB 深空灰色 移动联通电信4G手机",
        add_time: "2012-12-12 12:12:12",
        goods_no: "mageechenfdsfsdfs",
        stock_quantity: 20,
        market_price: 269,
        sel_price: 199
      };
    }
  },
  components: {
    "swiper-box": Swiper,
    "goddsinfo-number": GoodsInfoNumber
  }
};
</script>

<style lang="scss" scoped>
.goodsinfo-container {
  background-color: #eee;
  overflow: hidden;
  .now_price {
    color: red;
    font-size: 16px;
    font-weight: bold;
  }
}
.mui-card-footer {
  display: block;
  button {
    margin: 15px 0;
  }
}
.ball {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background-color: red;
  position: absolute;
  z-index: 99;
  top: 408px;
  left: 138px;
}
</style>
